/*
 * PatientAuswaehlen.java
 * 
 * Author: Malcolm 
 * Date: 24.05.2008
 * 
 * 
 */

package ocumed.applikation.patient;

import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;

import ocumed.applikation.domainhandling.DomainHandler;
import ocumed.applikation.exceptions.NoPatientException;
import ocumed.persistenz.dao.DAOFactory;
import ocumed.persistenz.dao.PatientDAO;
import ocumed.persistenz.hibernate.OcPatient;

public class PatientWaehlen {

	private PatientDAO m_patientDAO;
	private DomainHandler dh;


	public PatientWaehlen() {
		dh = DomainHandler.getInstance();
		m_patientDAO = DAOFactory.get(DAOFactory.RDBMS).getPatientDAO();
	}


	/**
	 * Gets a list of all patients and returns their id and last name.
	 * 
	 * @return HashMap containing all patients id and last name.
	 */
	public HashMap<Integer, String> getPatientenListe()
			throws NoPatientException {
		m_patientDAO.start();
		List<OcPatient> patListe = m_patientDAO.findAll();

		if (patListe.size() == 0) {
			throw new NoPatientException();
		}

		ListIterator<OcPatient> iter = patListe.listIterator();
		HashMap<Integer, String> patienten = new HashMap<Integer, String>();
		OcPatient currentPatient = new OcPatient();

		while (iter.hasNext()) {
			currentPatient = iter.next();
			String name = currentPatient.getPatientnachname().trim() + " "
					+ currentPatient.getPatientvorname().trim();
			patienten.put(currentPatient.getPatientid(), name);
		}

		return patienten;
	}


	public String getVersicherungsnummer(int patientId) {
		return new Integer(DomainHandler.pe.getDPatient(patientId)
				.getPatientid()).toString();
	}

}
